{% extends 'layout.html' %}

{% block css %}
    <link rel="stylesheet" type="text/css" href="/static/css/forms.css">
    <link rel="stylesheet" type="text/css" href="/static/css/base.css">
    <style>
        .content {
            margin-left: 20px;
        }
        .content a{
            display: block;
        }
    </style>
{% endblock %}

{% block menus %}
    {{ menu_string | safe }}
{% endblock %}

{% block content %}
<div  style="padding: 20px 40px">
    <h1>添加资产</h1>
{% if msg %}
    <div class="errornote">{{ msg }}</div>
{% endif %}

<form method="post" id="asset_form" novalidate>
<fieldset class="module aligned">
        <div class="form-row field-mod">
                <div>
        <label class="required">型号:</label>
                    <div class="related-widget-wrapper">
    <select name="type" required="" id="id_type">
      <option value="">---------</option>
        {% for row in type_list %}
            <option value="{{ row.id }}" >{{ row.name }}</option>
        {% endfor %}
    </select>
    <select name="mod" required="" id="id_mod">
      <option value="">---------</option>
        {% for row in mod_list %}
                <option value="{{ row.id }}">{{ row.name }}</option>
        {% endfor %}
    </select>
</div>
                </div>

        </div>
        <div class="form-row field-purchase_at">
                <div>
                        <label class="required" for="id_purchase_at">购买时间:</label>
                            <input type="date" name="purchase_at" class="vDateField" size="10"  ><span class="datetimeshortcuts"></span>
                </div>
        </div>
        <div class="form-row field-price">
                <div>
                        <label for="id_price">价格:</label>
                            <input type="text" name="price" class="vTextField" maxlength="32" id="id_price">
                </div>
        </div>
        <div class="form-row field-recipient">
                <div>
                        <label class="required" for="id_recipient">领用人:</label>

                            <div class="related-widget-wrapper">
    <select name="recipient" required="" id="id_recipient">
  <option value="">---------</option>
  {% for row in recipient_list %}
      {% if row.id == obj.recipient_id %}
        <option value="{{ row.id }}" selected>{{ row.name }}</option>
      {% else %}
        <option value="{{ row.id }}">{{ row.name }}</option>
      {% endif %}
  {% endfor %}
</select>

</div>
                </div>
        </div>
        <div class="form-row field-recipient_at">
                <div>
                        <label class="required" for="id_recipient_at">领用时间:</label>
                            <input type="date" name="recipient_at" class="vDateField" size="10" required=""><span class="datetimeshortcuts">&nbsp;</span>
                </div>
        </div>
        <div class="form-row field-sn">
                <div>
                        <label class="required" for="id_sn">资产编号:</label>
                            <input type="text" name="sn" class="vTextField" maxlength="32" required="" id="id_sn">
                </div>
        </div>
        <div class="form-row field-status">
                <div>
                        <label class="required" for="id_status">状态:</label>

                            <select name="status" id="id_status">

  {% for row in status_list %}
        <option value="{{ row.0 }}">{{ row.1 }}</option>
  {% endfor %}
</select>
                </div>
        </div>
        <div class="form-row field-note">
                <div>
                        <label for="id_note">备注:</label>
                            <input type="text" name="note" class="vTextField" maxlength="64" id="id_note" >
                </div>
        </div>
    <br>
<input type="submit" value="Save" class="default" style="float: left;margin-left: 10px">
</fieldset>




</form>
</div>
{% endblock %}

{% block js %}
    <script>
        $('#id_type').change(function () {
            ths = $(this).val()
            $.ajax({
                url: '/load_models',
                type: 'get',
                dataType: 'json',
                data:{type_info:ths},
                success:function (data) {
                    var shtml = ''
                    $.each(data,function (i,item) {
                        console.log(item)
                        shtml += '<option value='+ item.id + '>' + item.name + '</option>'
                    })
                    $('#id_mod').html(shtml)
                }
            })
        })
    </script>
{% endblock %}